package org.stwy.lease.contract;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.rap.common.persistence.IBaseDAO;

/**
 * 合同 DAO类
 */
/**
*版权信息 (c) RAP 保留所有权利.
*@author Rap.Codegen
*@Team RAP Team
*@Date 2015-4-17 20:48:15
*<p></p>
*
*@参与人：Rap.Codegen
*/
 
public interface ContractDAO extends IBaseDAO<ContractEntity, String> {
	@Query(" select max(a.theCode) from ContractEntity a")
	Long getLastCode();

	@Query(" select b from ContractEntity b where b.beginTs="
			+ "(select max(a.beginTs) from ContractEntity a where a.contractNum = ?1 and a.beginTs<=?2)"
			+ " and b.contractNum=?1 order by b.createTs desc")
	List<ContractEntity> findByNumAndDate(String contractNum, Date date);

	@Query(" from ContractEntity a where a.endDate<=?1 and a.contractState=1")
	List<ContractEntity> findNotEndContractsByEndDate(Date endDate);
	
	@Query(" select a.contractNum from ContractEntity a where a.contractNum like ?1% order by a.contractNum desc")
	String[] findLastContractNumByYearMonth(String yearMonth);
	
}
